package com.jblapp.icu.sms;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.content.Context;
import android.os.Handler;
import android.os.Message;

import com.jblapp.icu.http.Authentication;
import com.jblapp.icu.ui.RegisterConfirmActivity;

public class AuthenticationThread implements Runnable {
	private Context context = null;
	private String uniqId = null;
	private String telNumber = null;
	private Authentication authentication = null;
	private List<NameValuePair> params = null;
	private boolean isSuccess = false;
	private Message msg = null;
	private Handler msgHandler = null;

	public AuthenticationThread(Context context, String uniqId,
			String telNumber, Handler msgHandler) {
		this.context = context;
		this.uniqId = uniqId;
		this.telNumber = telNumber;
		this.msgHandler = msgHandler;
	}

	@Override
	public void run() {
		params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("mobilephone", telNumber));
		params.add(new BasicNameValuePair("uniqid", uniqId));
		authentication = new Authentication(params);
		try {
			isSuccess = authentication.isSuccess();
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (isSuccess) {
			msg = new Message();
			msg.what=RegisterConfirmActivity.READED_SMS;
			msgHandler.sendMessage(msg);
		}
	}
}
